package com.leyou.item.web;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecGroupService;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: YHL
 * @time: 2021/2/23 20:29
 */
@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecGroupService groupService;

  @Autowired
  private SpecParamService paramService;

    /**
     * 根据分类id查询对应的规格参数组集合
     * @param cid
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> listSpecGroupByCategory(
            @RequestParam("id")Long cid){

        return ResponseEntity.ok(this.groupService.listSpecGroupByCategory(cid));
    }

    /**
     * 根据规格参数组id查询对应的规格参数集合
     * @param gid
     * @param cid
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>>listSpecParm( @RequestParam(value = "groupId",required = false)Long gid,
                                                           @RequestParam(value = "categoryId",required = false)Long cid,
                                                           @RequestParam(value = "searching",required = false)Boolean searching){

        return ResponseEntity.ok(this.paramService.listSpecParm(gid,cid,searching));

    }
    /**
     * 根据分类id查询对应的规格参数组集合以及组内参数
     * @param cid
     * @return
     */
@GetMapping("/list")
    public ResponseEntity<List<SpecGroupDTO>>listSpecByCategory(@RequestParam("id")Long cid){

    return ResponseEntity.ok(this.groupService.listSpecByCategory(cid));

}


}
